function [ evaluation  ] = KFold(vehicles,class,learner_name,learner_opts,num_repeats)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here

%javaaddpath('C:\Program Files\Weka-3-6\weka.jar');
%evaluation = {};

for repeat=0:num_repeats-1
disp(['repeat ',num2str(repeat)])
%shuffle vehicles    
rand1=randperm(size(vehicles,2));
vehicles=vehicles(rand1);


testingMatrix = [];
traingingMatrix = [];

   temp_vehicle ={};

   
   %select number of bins: k
   if size(vehicles,2)==336
       k=8;
   else
       k=9;
   end
   n=size(vehicles,2)/k;
   hi_offset = n;
   low_offset = 1;
   for i=1:k
       temp_vehicle = vertcat(temp_vehicle,vehicles(low_offset:hi_offset));
       low_offset = low_offset +n;
       hi_offset = hi_offset+n;

   end

   
   counter = 1;
   while(counter <k+1)
   %pick training sample
       testingMatrix = temp_vehicle(counter,:)';

        traingingMatrix=reshape(temp_vehicle(1:counter-1,:),[1,(counter-1)*n]);
        traingingMatrix=horzcat(traingingMatrix, reshape(temp_vehicle(counter+1:end,:),[1,(k-counter)*n]));

   %save arff file to create weka object indirectly
   trainingfile = strcat('Training_fold', num2str(counter),'.arff');

   %create and save training data set
   writeFeaturesToArff(traingingMatrix, 'selected',class,trainingfile);
  
   %open them back to create java weka instance for training and testing
   weka_training = loadARFF(trainingfile);
   
   %Learner = trainWekaClassifier(weka_training,'functions.SMO','-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K "weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0"');
   Learner = trainWekaClassifier(weka_training,learner_name,learner_opts);
   rv = wekaTestLearner(Learner,testingMatrix', class);     
   evaluation(counter+k*repeat) = rv; 
   counter= counter+1;

   end
       
end   

end
